package com.jds.test.bio.p12;

import java.io.File;
import java.io.FileOutputStream;

/**
 * https://www.cnblogs.com/silyvin/articles/12078621.html
 * https://www.cnblogs.com/silyvin/articles/12083466.html
 * Created by joyce on 2019/12/21.
 */
public class FileClient {
    public static void main(String [] f) {

        /**
         * 如果缺少，连类加载器都不能加载了，让其提前加载
         * FileNotFoundException: /Users/joyce/work/netty/netty-test/target/classes/com/jds/test/bio/p12/Client.class (Too many open files in system)
         */
        Client client = new Client();
        run();
        Client.zuse();
    }

    /**
     * print 8489 不稳定
     * lsof -p 12322 |wc -l 8567 不稳定 执行该句时，应先打开terminal占用一个文件描述符
     */
    public static void run() {
        try {
            for(int i=0; i<20000; ++i) {
                File file = new File("/Users/joyce/Downloads/xx/xxxx"+i);
                file.createNewFile();
                FileOutputStream outputStream = new FileOutputStream(file);
                byte[] bytes = new byte[2];
                outputStream.write(bytes);
                System.out.println(i+1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
